import { ipcRenderer } from "electron";
import { ISession, ITogglePinSessionParams } from "../types/session.ts";

export const SessionPreload = {
  //  更新session
  updateSessionByField: (sessionId: string, ownerId: number, data: any) => {
    return ipcRenderer.invoke("getLocalSession", sessionId, ownerId, data);
  },

  // 获取本地session
  getLocalSession: (userId: number) => {
    return ipcRenderer.invoke("getLocalSession", userId);
  },

  // 存储本地session
  storeLocalSession: (session: ISession) => {
    return ipcRenderer.invoke("storeLocalSession", session);
  },

  // 置顶 session
  togglePinSession: (params: ITogglePinSessionParams) => {
    return ipcRenderer.invoke("togglePinSession", params);
  },

  // 删除 sesion
  softDeleteSession: (sessionId: string, ownerId: number) => {
    return ipcRenderer.invoke("softDeleteSession", sessionId, ownerId);
  },

  // 添加session
  addSession: (session: ISession) => {
    return ipcRenderer.invoke("addSession", session);
  },

  // 处理未读消息
  handelUnread: (sessionId: string, ownerId: number) => {
    return ipcRenderer.invoke("handelUnread", sessionId, ownerId);
  },

  // 获取本地message
  getLocalMessage: (sessionId: string, ownerId: number) => {
    return ipcRenderer.invoke("getLocalMessage", sessionId, ownerId);
  },
};
